package com.gscitysfy.cus.drain.modules.pipe.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.pipe.entity.DrainPipeHiddenDangerAnalyse;
import com.gscitysfy.cus.drain.modules.pipe.service.IDrainPipeHiddenDangerAnalyseService;
import com.gscitysfy.cus.drain.modules.pipe.vo.HiddenDangerAnalyseQueryVo;
import com.gscitysfy.cus.drain.modules.pipe.vo.HiddenDangerAnalyseVo;
import groovy.lang.Lazy;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 隐患分析 前端控制器
 * </p>
 *
 * @author Axi
 * @since 2022-11-16 12:06:33
 */
@RestController
@RequestMapping("/pipe/analyse")
@Tag(name = "管网隐患管理 -> 隐患分析")
public class DrainPipeHiddenDangerAnalyseController {

    @Resource
    @Lazy
    IDrainPipeHiddenDangerAnalyseService analyseService;

    @Operation(summary = "查询隐患列表", description = "查询隐患列表接口")
    @PostMapping("/pageList")
    @DictTranslation({
            @FieldParam(dictType = DicConstant.HIDDEN_DANGER_SOURCE, targetField = "hiddenDangerSource"),
            @FieldParam(dictType = DicConstant.HIDDEN_DANGER_CATEGORY, targetField = "hiddenDangerCategory")
    })
    public Result<IPage<DrainPipeHiddenDangerAnalyse>> getPageList(@RequestBody HiddenDangerAnalyseQueryVo queryVo) {
        return Result.content(analyseService.getPageList(queryVo));
    }

    @PostMapping("/add")
    @Operation(summary = "新增隐患", description = "新增隐患接口")
    public Result<Boolean> add(@RequestBody HiddenDangerAnalyseVo analyseVo) {
        return analyseService.add(analyseVo) ? Result.success() : Result.failure();
    }

    @Operation(summary = "删除隐患", description = "删除隐患接口")
    @DeleteMapping("/delete")
    public Result<Boolean> delete(String ids) {
        return analyseService.delete(ids) ? Result.success() : Result.failure();
    }

    @Operation(summary = "修改隐患", description = "修改隐患接口")
    @PutMapping(value = "/update")
    public Result<Boolean> update(@RequestBody HiddenDangerAnalyseVo analyseVo) {
        return analyseService.update(analyseVo) ? Result.success() : Result.failure();
    }

}
